package com.steven.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.steven.domain.Person;

public class ObjectStreamDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		readObject();
	

	}

	private static void readObject() {
		 
		ObjectInputStream ois=null;

		try {
			  ois = new ObjectInputStream(new FileInputStream(new File("object.txt")));
		 Person p = (Person)	ois.readObject();
		System.out.println(p);
		   p = (Person)	ois.readObject();
			System.out.println(p);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
 try {
	ois.close();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
	}

	private static void writeObject() {
		ObjectOutputStream oos =null;
		try {
			  oos = new ObjectOutputStream(new FileOutputStream("object.txt"));
			
			oos.writeObject(new Person("yangdongping",31));
			oos.writeObject(new Person("yangdongping1",311));
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			oos.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
